﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
using OnlineBusTicket.Component;

namespace OnlineBusTicket
{
    public partial class Register : System.Web.UI.Page
    {
      //  SqlConnection connection=new SqlConnection(WebConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
       
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }

        protected void imgbtnRegister_Click(object sender, ImageClickEventArgs e)
        {
            try
            {

                var check = Membership.GetUser(txtUserName.Text);
                if (check != null)
                {
                    // announcement;
                    return;
                }
                var membershipUser = Membership.CreateUser(txtUserName.Text, txtPassword.Text, txtEmail.Text);
                //Roles.AddUserToRole((sender as CreateUserWizard).UserName, "Member");  neu sai tool
                Roles.AddUserToRole(txtUserName.Text, "Member");

                using (var db = new OnlineBusTicketEntities())
                {
                    var member = new Member();
                    member.UserName = txtUserName.Text;
                    member.MemberId = txtMemberId.Text;
                    member.FullName = txtFirstName.Text;
                    member.Gender = rbMale.Checked;
                    member.Age = Convert.ToInt32(txtAge.Text);
                    member.Address = txtAddress.Text;
                    member.Phone = txtPhone.Text;

                    db.Members.AddObject(member);
                    db.SaveChanges();


                }

                Response.Redirect("Home.aspx");
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(ex.Message);
            }
         }
    }
}
